<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../manager/base.jsp"%>
<script type="text/javascript" src="${ctx}/layui/layui.all.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/layui/css/layui.css">

<script type="text/javascript" src="${ctx}/js/layui_common.js"></script>
<script type="text/javascript">
	$(function() {
		//自适应屏幕宽度

		var main_h = $(window).height();
		$('.hy_list').css('height', main_h - 45 + 'px');

		var main_w = $(window).width();
		$('.xjhy').css('width', main_w - 40 + 'px');

		$(".tabBox .tabCont:first").css("display", "block");
		$(".tabBox .tabNav li").click(
				function() {
					$(this).siblings("li").removeClass("now");
					$(this).addClass("now");
					$(this).parents(".tabBox").find(".tabCont").css("display",
							"none");
					var i = $(this).index();
					$(this).parents(".tabBox").find(".tabCont:eq(" + i + ")")
							.css("display", "block");
				});

		$('.xial_m span').click(function() {
			$(this).parent('.xial_m').siblings('.xl_ctn').toggle();
		});
	});
	<!--框架高度设置-->
</script>
<script type="text/javascript">
	$(function() {
		
	})

	function getUserInfoByName() {
		var username = $("input[name='username']").val();
		getUserInfo(username);
	}

	function getUserInfo(username) {
		var i;
		$
				.ajax({
					url : '${ctx}/getUserInfo',
					data : {
						"username" : username
					},
					type : 'get',
					dataType : 'json',
					async : false,
					beforeSend : function() {
						i = layer.open({
							type : 3,
							area : '500px',
							skin : 'layui-layer-molv',
							shade : 0.5,
							shadeClose : true,
							maxmin : true
						});
					},
					success : function(data) {
						layer.close(i);
						$("#userInfo").html("");
						if (data != null) {
							$
									.each(
											data,
											function(index, item) {
												var html = "";
												html += "<tr>";
												html += "<td>" + item.username
														+ "</td>";
												html += "<td>"
														+ item.createtime
														+ "</td>";
												/* html += "<td>"+item.identity+"</td>";  */
												html += "<td>";
												if (item.username != "admin") {
													html += "<a href=\"javascript:void(0);\" class=\"btn\" onclick=\"updateUser('"
															+ item.uuid
															+ "')\">修改</a>";
													html += "<a href=\"javascript:void(0);\" class=\"btn\" onclick=\"deleteUser('"
															+ item.uuid
															+ "')\">删除</a>";
												}
												html += "</td>";
												html += "</tr>";
												$("#userInfo").append(html);
											});

						}
						//添加分页
						//计算总数
						var total = 0;
						if (data == null) {
							total = 0;
						} else if (data.length == 0 || data[0].cnt == null
								|| data[0].cnt == ""
								|| data[0].cnt == undefined) {
							total = 0;
						} else {
							total = data[0].cnt;
						}
						//定义一个laypage实例
						var laypage = layui.laypage;
						laypage
								.render({
									elem : 'r_foot_m', //注意，这里的 test1 是 ID，不用加 # 号
									count : total,
									prev : '上一页',
									next : '下一页',
									cont : 'claimpage',
									skin : 'yahei',
									jump : function(obj, first) {
										if (first != true) {//是否首次进入页面
											var currentPage = obj.curr;//获取点击的页码
											//通过当前页数，获取对应的数据
											$
													.ajax({
														url : '${ctx}/getUserInfo',
														data : {
															"username" : username,
															"page" : currentPage
														},
														type : 'get',
														dataType : 'json',
														beforeSend : function() {
															i = layer
																	.open({
																		type : 3,
																		area : '500px',
																		skin : 'layui-layer-molv',
																		shade : 0.5,
																		shadeClose : true,
																		maxmin : true
																	});
														},
														success : function(data) {
															console.log(data);
															layer.close(i);
															$("#userInfo")
																	.html("");
															if (data != null) {
																$
																		.each(
																				data,
																				function(
																						index,
																						item) {

																					var html = "";
																					html += "<tr>";
																					html += "<td>"
																							+ item.username
																							+ "</td>";
																					html += "<td>"
																							+ item.createtime
																							+ "</td>";
																					/* html += "<td>"+item.identity+"</td>"; */
																					html += "<td>";
																					html += "<a href=\"javascript:void(0);\" class=\"btn\" onclick=\"deleteUser('"
																							+ item.uuid
																							+ "')\">删除</a>";
																					html += "<a href=\"javascript:void(0);\" class=\"btn\" onclick=\"getAllRoleInfo('"
																							+ item.uuid
																							+ "')\">授予角色</a>";
																					html += "</td>";
																					html += "</tr>";
																					$(
																							"#userInfo")
																							.append(
																									html);
																				});
															}
														},
														error : function(data) {
															layer.close(i);
														}
													});
										}
									}
								//数据总数，从服务端得到
								});
					}
				});
	}
</script>
<script>
	//通过所有的角色，并获取用户赋予的角色
	var roleindex;
	function getAllRoleInfo(uuid) {
		$
				.ajax({
					url : '${ctx}/role/getAllRoleInfo',
					data : {
						"uuid" : uuid
					},
					type : 'get',
					dataType : 'json',
					success : function(data) {
						if (data != null) {
							//遍历数据，拼接html
							var html = '<div>';
							html += '<div class="search">';
							html += '	<a href="javascript:void(0);" class="btn" onclick="putRoleInfo(\''
									+ uuid + '\')">设置</a>';
							html += '</div>';
							html += '<table cellpadding="0" cellspacing="0" class="list_hy" style="width:550px;">';
							html += '	<tr>';
							html += '		<th class="xz" scope="col">选择</th>';
							html += '		<th scope="col">角色名</th>';
							html += '	</tr>';
							html += '<tbody id="setupFun">';
							if (data != null) {
								$
										.each(
												data,
												function(index, item) {
													html += '	<tr>';
													if (item.ischecked == 1) {
														html += '		<td class="xz"><input name="setupfun" type="radio" id="'+item.id+'" value="'+item.id+'" checked="checked"></td>';
													} else {
														html += '		<td class="xz"><input name="setupfun" type="radio" id="'+item.id+'" value="'+item.id+'"></td>';
													}
													html += '		<td>'
															+ item.name
															+ '</td>';
													html += '	</tr>';
												});
							}
							html += '</tbody></table></div>';
							html += '<div class="r_foot">';
							html += '	<div class="r_foot_m" id="setup_function">';
							html += '	</div>';
							html += '</div>';
							//打开弹框，显示角色列表
							roleindex = layer.open({
								type : 1,
								title : '角色列表',
								area : [ '600px', '360px' ],
								shadeClose : true, //点击遮罩关闭
								content : html
							});
						} else {
							//提示先添加角色，再进行配置
						}
					}
				});
	}
	function putRoleInfo(uuid) {
		var roleid = $("input[type='radio'][name='setupfun']:checked").val();
		$.ajax({
			url : '${ctx}/user/putRoleInfo',
			data : {
				"uuid" : uuid,
				"roleid" : roleid
			},
			type : 'post',
			dataType : 'html',
			success : function(data) {
				if (data == "success") {
					layer.alert("设置成功!", function() {
						window.location.reload();
						parent.layer.close(roleindex);
					});
				}
			}
		});
	}
</script>
<script>
	//大学信息集合
	function getAllUniversityInfo(univerid) {
		var optionHtml = "<option value=\"\">请选择</option>";
		$
				.ajax({
					url : '${ctx}/university/getAllUniversityInfo',
					data : {},
					type : 'get',
					async : false,
					dataType : 'json',
					success : function(data) {
						if (data != null) {
							$
									.each(
											data,
											function(index, item) {
												if (item.id == univerid) {
													optionHtml += '<option value="'+item.id+'" selected="selected">'
															+ item.name
															+ '</option>';
												} else {
													optionHtml += '<option value="'+item.id+'">'
															+ item.name
															+ '</option>';
												}
											})
						}
					}
				});
		return optionHtml;
	}
	//通过大学id获取院信息
	/**
	 * collegeid 院id
	 pname 院所属select的name
	 name  系所属select的name
	 */

	//获取系信息 
	/*majorid 专业id
	 * pname 系name
	 * name 班name
	 */
	function getCollsystemInfo(majorid, pname, name) {
		//把专业，班级清空
		$("select[name='major_name']").val("");
		$("select[name='classify_name']").val("");

		var collegeid = $("select[name='" + pname + "'] option:selected").val();
		var majorHtml = getCollsystemHtml(collegeid, majorid);
		$("select[name='" + name + "']").html(majorHtml);
	}
	//获取系html
	function getCollsystemHtml(collegeid, collsystemid) {
		var optionHtml = "<option value=\"\">请选择</option>";
		$
				.ajax({
					url : '${ctx}/collsystem/getCollsystemHtml',
					data : {
						"collegeid" : collegeid
					},
					type : 'get',
					dataType : 'json',
					async : false,
					success : function(data) {
						if (data != null) {
							$
									.each(
											data,
											function(index, item) {
												if (item.id == collsystemid) {
													optionHtml += '<option value="'+item.id+'" selected="selected">'
															+ item.name
															+ '</option>';
												} else {
													optionHtml += '<option value="'+item.id+'" >'
															+ item.name
															+ '</option>';
												}
											});
						}
					}
				});
		return optionHtml;
	}

	//获取专业信息 
	/*classifyid 班级id
	 * pname 专业name
	 * name 班级name
	 */
	function getMajorInfo(majorid, pname, name) {
		//把班级清空
		$("select[name='classify_name']").val("");

		var collsystemid = $("select[name='" + pname + "'] option:selected")
				.val();
		var classifyHtml = getMajorHtml(collsystemid, majorid);
		$("select[name='" + name + "']").html(classifyHtml);
	}
	//获取专业html
	function getMajorHtml(collsystemid, majorid) {
		var optionHtml = "<option value=\"\">请选择</option>";
		$
				.ajax({
					url : '${ctx}/major/getMajorBySystemid',
					data : {
						"systemid" : collsystemid
					},
					type : 'get',
					dataType : 'json',
					async : false,
					success : function(data) {
						if (data != null) {
							$
									.each(
											data,
											function(index, item) {
												if (item.id == majorid) {
													optionHtml += '<option value="'+item.id+'" selected="selected">'
															+ item.name
															+ '</option>';
												} else {
													optionHtml += '<option value="'+item.id+'" >'
															+ item.name
															+ '</option>';
												}
											});
						}
					}
				});
		return optionHtml;
	}

	//获取班级信息 
	/*majorid 专业id
	 * pname 专业name
	 * name 班级name
	 */
	function getClassifyInfo(classifyid, pname, name) {
		var majorid = $("select[name='" + pname + "'] option:selected").val();
		var classifyHtml = getClassifyHtml(majorid, classifyid);
		$("select[name='" + name + "']").html(classifyHtml);
	}

	function getClassifyHtml(majorid, classifyid) {
		var optionHtml = "<option value=\"\">请选择</option>";
		$
				.ajax({
					url : '${ctx}/classify/getClassifyByMajor',
					data : {
						"majorid" : majorid
					},
					type : 'get',
					dataType : 'json',
					async : false,
					success : function(data) {
						if (data != null) {
							$
									.each(
											data,
											function(index, item) {
												if (item.id == classifyid) {
													optionHtml += '<option value="'+item.id+'" selected="selected">'
															+ item.name
															+ '</option>';
												} else {
													optionHtml += '<option value="'+item.id+'" >'
															+ item.name
															+ '</option>';
												}
											});
						}
					}
				});
		return optionHtml;
	}
</script>
<script type="text/javascript">
	//打开弹框 授予角色
	var index;
	function updateUser(uuid) {
		//通过id查询角色信息
		$
				.ajax({
					url : '${ctx}/getUserInfo',
					data : {
						"uuid" : uuid
					},
					type : 'get',
					dataType : 'json',
					async : false,
					success : function(data) {
						$
								.each(
										data,
										function(index, item) {
											//添加下拉内容
											if (data != null) {
												//				var selectInfo = getFunParentName(data.pid);
												var html = "";
												html += '<div class="tabCont">';
												html += '<input type="hidden" id="updateid" value="'+item.uuid+'"/>';
												html += '<ul class="hypz">';
												html += '	<li class="clearfix"><span class="title">用户名称：</span>';
												html += '		<div class="li_r">';
												html += '			<input class="chang" name="user_update_name" type="text" value="'+item.username+'"> <i>*</i>';
												html += '		</div></li>';
												html += '	<li class="tj_btn"><a href="javascript:void(0);" onclick="updateUserInfo();">修改</a></li>';
												html += '</ul>';
												html += '</div>';
												//打开弹框，显示
												index = layer
														.open({
															type : 1,
															title : '用户修改',
															area : [ '600px',
																	'360px' ],
															shadeClose : true, //点击遮罩关闭
															content : html
														});
											}
										});
					}
				});
	}

	function updateUserInfo() {
		var uuid = $("#updateid").val();
		var username = $("input[name='user_update_name']").val();
		if (username == null || username == "" || username == undefined) {
			//提示不能为空
			layer.alert("用户名不能为空!");
			return;
		}
		$.ajax({
			url : '${ctx}/updateUserInfo',
			data : {
				"uuid" : uuid,
				"username" : username
			},
			type : 'post',
			dataType : 'html',
			success : function(data) {
				if (data == "success") {
					layer.alert("修改成功!", function() {
						window.location.reload();
						parent.layer.close(index);
					});
				}
			}
		});
	}
</script>
<script type="text/javascript">
	//删除角色
	function deleteUser(uuid) {
		layer.confirm('确定要删除这个用户吗?', {
			icon : 3,
			title : '提示'
		}, function(index) {
			$.ajax({
				url : '${ctx}/deleteUserInfo',
				data : {
					"uuid" : uuid
				},
				type : 'post',
				dataType : 'html',
				success : function(data) {
					if (data == "success") {
						layer.alert("删除成功!", function() {
							window.location.reload();
							parent.layer.close(index);
						});
					}
				}
			});
		});
	}
</script>
<script type="text/javascript">
	function addMaintenanceInfo() {
		var maintainItems = $("input[name='maintain_items']").val();
		var maintainer = $("input[name='maintainer']").val();
		$.ajax({
			url : '${ctx}/maintenance/addMaintenanceInfo',
			data : {
				"maintainItems" : maintainItems,
				"maintainer" : maintainer
			},
			type : 'post',
			dataType : 'html',
			success : function(data) {
				console.log(data);
				if (data == "success") {
					layer.alert("添加成功!", function() {
						window.location.reload();
						parent.layer.close(index);
					});
				} else{
					layer.alert("添加失败!");
				}
			}
		});
	}
</script>
<div id="right_ctn">
	<div class="right_m">
		<!--列表-->
		<div class="hy_list">
			<div class="box_t">
				<span class="name">设备维护记录列表</span>
				<!--当前位置-->
				<div class="position">
					<a href=""><img src="${ctx}/images/icon5.png" alt="" /></a> <a
						href="">首页</a> <span><img src="${ctx}/images/icon3.png"
						alt="" /></span> <a href="">设备管理</a> <span><img
						src="${ctx}/images/icon3.png" alt="" /></span> <a href="">维护记录</a>
				</div>
				<!--当前位置-->
			</div>

			<!--新建权限-->
			<form action="" method="post">
				<div class="xjhy" style="padding: 0px;">
					<div class="tabBox_t">
						<div class="tabBox">
							<ul class="tabNav">
								<li class="now"><span>记录查询</span></li>
								<li><span>添加记录</span></li>
							</ul>
							<div class="tabCont" style="display: block; overflow: auto;">
								<!--所有权限-->
								<ul class="hypz gjpz clearfix">
									<!--查询-->
									<div class="search">
										<span>按设备的名称查询：</span>
										<div class="s_text">
											<input name="device_name" type="text">
										</div>
										<a href="javascript:void(0);" class="btn"
											onclick="getByName()">查询</a>
									</div>
									<!--查询-->
									<div class="space_hx">&nbsp;</div>
									<!--列表-->
									<form action="" method="post">
										<table cellpadding="0" cellspacing="0" class="list_hy"
											style="width: 98%;">
											<tr>
												<th scope="col">维护项目</th>
												<th scope="col">维护人员</th>
												<th scope="col">操作</th>
											</tr>
											<tbody id="userInfo">
											</tbody>
										</table>
										<!--列表-->
										<!--右边底部-->
										<div class="r_foot">
											<div class="r_foot_m" id="r_foot_m"></div>
										</div>
									</form>
									<!--右边底部-->
								</ul>
								<!--所有权限-->
							</div>
							<div class="tabCont" style="height: 515px; overflow: auto;">
								<!--添加权限-->
								<ul class="hypz">
									<!-- <li class="clearfix"><span class="title">输入密码：</span>
										<div class="li_r">
											<input class="chang" name="password" type="password"> <i>*</i>
										</div></li> -->
									<li class="clearfix"><span class="title">维护项目：</span>
										<div class="li_r">
											<input class="chang" name="maintain_items" type="text"> <i>*</i>
										</div></li>
									<li class="clearfix"><span class="title">维护人员：</span>
										<div class="li_r">
											<input class="chang" name="maintainer" type="text"> <i>*</i>
										</div></li>
									<!-- <li class="clearfix"><span class="title">检查人员：</span>
										<div class="li_r">
											<input class="chang" name="checker" type="text"> <i>*</i>
										</div></li>

									<li class="clearfix"><span class="title">评定结果：</span>
										<div class="li_r">
											<select id="rating" name="rating" lay-verify="">
												<option value="">请选择</option>
												<option value="1">合格</option>
												<option value="0">不合格</option>
											</select> <i>*</i>
										</div></li> -->
									<!-- <li class="clearfix"><span class="title">用户身份：</span>
										<div class="li_r">
											<select name="user_identity" lay-verify="">
												<option value="">请选择</option>
												<option value="2">老师</option>
												<option value="1">学生</option>
												<option value="0">后台</option>
											</select> <i>*</i>
										</div></li> -->
									<!-- <li class="clearfix"><span class="title">所属大学：</span>
										<div class="li_r">
											<select name="university_name" lay-verify="" onchange="getCollegeInfo('','university_name','college_name');">
												<option value="">请选择</option>
											</select> <i>*</i>
										</div></li> -->
									<!-- <li class="clearfix"><span class="title">所属院：</span>
										<div class="li_r">
											<select name="college_name" lay-verify="" onchange="getCollsystemInfo('','college_name','collsystem_name');">
												<option value="">请选择</option>
											</select> <i>*</i>
										</div></li>
									<li class="clearfix"><span class="title">所属系：</span>
										<div class="li_r">
											<select name="collsystem_name" lay-verify="" onchange="getMajorInfo('','collsystem_name','major_name')">
												<option value="">请选择</option>
											</select> <i>*</i>
										</div></li>
									<li class="clearfix"><span class="title">所属专业：</span>
										<div class="li_r">
											<select name="major_name" lay-verify="" onchange="getClassifyInfo('','major_name','classify_name')">
												<option value="">请选择</option>
											</select> <i>*</i>
										</div></li>
									<li class="clearfix"><span class="title">所属班级：</span>
										<div class="li_r">
											<select name="classify_name" lay-verify="">
											  <option value="">请选择</option>
											</select> <i>*</i>
										</div></li> -->
									<li class="tj_btn"><a href="javascript:void(0);"
										onclick="addMaintenanceInfo();">添加</a></li>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
		<!--列表-->
	</div>
</div>